#include <iostream>
#include <vector>
#include <string>
#include <Vector.hpp>
using namespace std;

class Solution
{
public:
    vector<string> generateParenthesis(int n)
    {
        vector<string> res;
        string path;
        bt(res, path, n, n);
        return res;
    }

    // left-right parenthey unplaced
    void bt(vector<string> &res, string s, int left, int right)
    {
        if (left == 0 && right == 0)
        {
            res.push_back(s);
            return;
        }
        if (right < left || left < 0 || right < 0)
        {
            return;
        }
        if (left > 0)
        {
            bt(res, s + "(", left - 1, right);
        }
        if (right > 0)
        {
            bt(res, s + ")", left, right - 1);
        }
    }
};

int main()
{
    cout << "Code22" << endl;
    Solution s;
    vector<string> res = s.generateParenthesis(3);
    PrintVector(res);
    return 0;
}